package org.smart4j.chapter.service;

/**
 * Created by chinalin on 2017/3/23.
 */

import org.slf4j.Logger;
import org.smart4j.chapter.helper.DatabaseHelper;
import org.smart4j.chapter.model.Customer;
import org.smart4j.framework.annotation.Service;
import org.smart4j.framework.annotation.Transaction;

import java.util.List;
import java.util.Map;

/**
 * Created by chinalin on 2017/3/13.
 */
@Service
public class CustomerService {

    private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(CustomerService.class);

    /**
     * 获取客户列表
     */
    public List<Customer> getCustomerList(){
        String sql = "SELECT * FROM customer" ;
        return DatabaseHelper.queryEntityList(Customer.class, sql) ;
    }


    /**
     * 获取客户
     */
    public Customer getCustomer(long id){
        String sql = "SELECT * FROM customer WHERE id=?" ;
        return DatabaseHelper.queryEntity(Customer.class,sql,id) ;
    }

    /**
     * 创建客户
     */
    @Transaction
    public boolean createCustomer(Map<String,Object> fieldMap){
        return DatabaseHelper.insertEntity(Customer.class,fieldMap);
    }

    /**
     * 更新客户
     */
    @Transaction
    public boolean updateCustomer(long id, Map<String,Object> fieldMap){
        return DatabaseHelper.updateEntity(Customer.class,id,fieldMap);
    }

    /**
     * 删除客户
     */
    @Transaction
    public boolean deleteCustomer(long id){
        return DatabaseHelper.deleteEntity(Customer.class,id);

    }
}
